import networkx as nx
import numpy as np
import web_page_generate
import matplotlib.pyplot as plt

if __name__ == "__main__":
    num = 50
    d = np.zeros(num)
    N = np.zeros(num)
    k = np.zeros(num)
    C = np.zeros(num)
    for i in range(num):
        g:nx.Graph = web_page_generate.web_page((i+1)*100, 5, 0.7).to_undirected()
        # g = nx.newman_watts_strogatz_graph((i+1)*100, 8, 0.05)
        lc:nx.Graph = g.subgraph(max(nx.connected_components(g), key=len))
        d[i] = nx.average_shortest_path_length(lc)
        N[i] = lc.number_of_nodes()
        k[i] = 2*lc.number_of_edges()/lc.number_of_nodes()
        C[i] = nx.average_clustering(g)
        print(f"{i}: d {d[i]}, N {N[i]}, k {k[i]}, C {C[i]}")
    plt.xlabel("the number of graph")
    plt.plot(d, label='d')
    plt.plot(np.log(N)/np.log(k), label='lnN/lnk')
    plt.plot(np.log(N), label='lnN')
    plt.grid()
    plt.legend()
    plt.show()
